package com.tgpms.web.excelTable.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PutMapping;
import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
import com.tgpms.auth.security.TokenService;
import java.io.Serializable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.tgpms.common.Result;
import com.tgpms.web.excelTable.entity.ExcelTableTemplate;
import com.tgpms.web.excelTable.service.IExcelTableTemplateService;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 动态表格模板表 控制层
 * </p>
 *
 * @author newway
 * @since 2020-01-17
 */
@Api(value = "ExcelTableTemplateController", tags = "动态表格模板表相关接口")
@RestController
@RequestMapping("/ev/ExcelTableTemplate")
public class ExcelTableTemplateController {

	private final Logger log = LoggerFactory.getLogger(ExcelTableTemplateController.class);
	
	@Resource
	private IExcelTableTemplateService service;
	@Resource
	private TokenService tokenService;
	
	@ApiOperation(value = "新增动态表格模板表接口",notes = "新增动态表格模板表接口",httpMethod = "POST")
	@PostMapping(value = "/addExcelTableTemplateInfo")
	public Result addExcelTableTemplateInfo(@RequestBody ExcelTableTemplate en,HttpServletRequest request) {
		log.info("新增动态表格模板表接口接收到的参数为: "+en.toString());
		Result result = new Result();
		try{
			String insertName = tokenService.getUserName(request);
			en.setInsertUser(insertName);
			result = service.addExcelTableTemplate(en,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("增加异常");
			return result;
		}
		return result;
	}
	
	@ApiOperation(value = "修改动态表格模板表接口",notes = "修改动态表格模板表接口",httpMethod = "PUT")
	@PutMapping(value = "/updateExcelTableTemplateInfo")
	public Result updateExcelTableTemplateInfo(@RequestBody ExcelTableTemplate en,HttpServletRequest request) {
		log.info("修改动态表格模板表接口接收到的参数为: "+en.toString());
		Result result = new Result();
		try{
			String insertName = tokenService.getUserName(request);
			en.setModifyUser(insertName);
			result = service.updateExcelTableTemplate(en,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("修改异常");
			return result;
		}
		return result;
	}
	
	@ApiOperation(value = "删除动态表格模板表接口",notes = "删除动态表格模板表接口",httpMethod = "DELETE")
	@DeleteMapping(value = "/deleteExcelTableTemplateInfo")
	public Result deleteExcelTableTemplateInfo(@RequestParam Serializable id,HttpServletRequest request) {
		log.info("删除动态表格模板表接口接收到的参数为: {id: "+id+" }");
		Result result = new Result();
		try{
			result = service.deleteExcelTableTemplate(id,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("删除异常");
			return result;
		}
		return result;
	}
}
